package com.wei.duowan.bbs.ui.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

import com.wei.duowan.bbs.presenter.BasePresenter;

/**
 * 作者：赵若位
 * 时间：2019/8/23 15:08
 * 联系方式：1070138445
 * 功能：基于Lazy Loading实现的Fragment
 */
public abstract class BaseLazyFragment<T extends BasePresenter> extends BaseFragment<T>
{
    /*布局View是否加载完毕*/
    private boolean isViewCreated = false;
    /*当前布局用户是否可见*/
    private boolean isViewToUser = false;


    @Override
    public void setUserVisibleHint(boolean isVisibleToUser)
    {
        super.setUserVisibleHint(isVisibleToUser);
        isViewToUser = isVisibleToUser;
        if (isVisibleToUser)
        {
            loadingData();
        }
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
    {
        super.onViewCreated(view, savedInstanceState);
        isViewCreated = true;
        loadingData();
    }

    private void loadingData()
    {
        if (isViewCreated && isViewToUser)
        {
            initData();
            isViewCreated = false;
        }
    }

    public void initData()
    {

    }
}
